<template>
  <div class='container'>
    <el-row>
      <el-col :span='24'>
        <el-card>
          <div slot="header">
            <bread></bread>
          </div>

          <div class="business-table">
            <el-row>
              <el-form class="form" label-width="100px" :model="incomePayData">
                <el-col :span="16">
                  <el-col :span="12">
                    <el-form-item label="商家名称">
                      <el-input v-model="incomePayData.shopName" size="mini" placeholder="请输入商家简称"></el-input>
                    </el-form-item>
                    <el-form-item label="所属行业">
                      <el-select @change="getTradeList($event)" v-model="incomePayData.classifyId" placeholder="请选择"
                                 style="width:100%">
                        <el-option
                          v-for="item in tradeList"
                          :key="item.id"
                          :label="item.title"
                          :value="item.id">
                          <span style="float: left">{{ item.title }}</span>
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>

                  <el-col :span="12">
                    <el-form-item label="商家编号">
                      <el-input v-model="incomePayData.shopCode" size="mini"
                                placeholder="请输入商家编号"></el-input>
                    </el-form-item>
                    <el-form-item label="联系电话">
                      <el-input v-model="incomePayData.mobile" size="mini"
                                placeholder="请输入联系电话"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col>
                    <el-form-item label="所属区域">
                      <el-cascader
                        ref="address"
                        size="large"
                        :options="optionProps"
                        v-model="selectedOptions"
                        @change="handleChange">
                      </el-cascader>
                    </el-form-item>
                  </el-col>
                </el-col>

                <el-col :span="8">
                  <el-form-item></el-form-item>
                  <el-form-item></el-form-item>
                  <el-form-item></el-form-item>
                  <el-form-item>
                    <el-button @click="submitSearch()">搜索</el-button>
                    <el-button @click="clearListSearch">重置</el-button>
                  </el-form-item>
                </el-col>
              </el-form>
            </el-row>

            <div class="table-wrapper">
              <el-table
                :data="businessList"
                style="width: 100%"
                align='center'
                :header-cell-style="{background:'#eef1f6'}"
                @selection-change="handleSelectionChange"
              >

                <el-table-column
                  type="selection"
                  align='center'
                  width="50">
                </el-table-column>
                <el-table-column
                  prop="shopCode"
                  label="商家编号"
                  align='center'
                  width="100">
                </el-table-column>
                <el-table-column
                  prop="createTime"
                  label="商家入住时间"
                  align='center'
                  width="150"
                >
                </el-table-column>
                <el-table-column
                  prop="shopName"
                  label="商家名称"
                  align='center'
                  width="150"
                >
                </el-table-column>
                <el-table-column
                  prop="shopClassify"
                  label="所属行业"
                  align='center'
                  width="120">
                </el-table-column>
                <el-table-column
                  label="所属城市"
                  align='center'
                >
                  <template slot-scope="scope">
                    {{scope.row.province}}{{scope.row.city}}{{scope.row.county}}
                  </template>
                </el-table-column>
                <el-table-column
                  prop="serviceTel"
                  label="联系电话"
                  align='center'
                  width="120">
                </el-table-column>
                <el-table-column
                  prop="scale"
                  label="分配比例"
                  align='center'
                  width="80">
                </el-table-column>
                <el-table-column
                  prop="pensionScale"
                  label="养老金分配比例"
                  align='center'
                  width="100">
                </el-table-column>
                <el-table-column
                  align='center'
                  label="操作"
                  width="180">
                  <template slot-scope='scope'>
                    <el-button
                      type="text"
                      size="mini"
                      @click='onEdit(scope.$index, scope.row)'
                    >
                      <!--              <router-link tag="span" to="">编辑信息</router-link>-->
                      编辑信息
                    </el-button>
                    <el-button
                      type="text"
                      size="mini"
                      @click='onCheck(scope.$index, scope.row)'
                    >
                      <!--              <router-link tag="span" to="businessLook">查看商家</router-link>-->
                      查看商家
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>

              <div class="table-footer">
                <el-row>
                  <el-col>
                    <el-button @click="frozenBusiness" size="small"
                               v-if="tabsName == 1 && $route.name == 'businessCheck'">
                      冻结商家
                    </el-button>
                    <el-button @click="" size="small" v-if="tabsName == 1 && $route.name == 'businessCheck'">审核驳回
                    </el-button>
                    <el-button @click="" size="small" v-if="tabsName == 1 && $route.name == 'businessCheck'">审核通过
                    </el-button>
                    <el-button @click="" size="small" v-if="tabsName == 3">解除冻结</el-button>
                  </el-col>
                </el-row>
              </div>
            </div>
          </div>

          <div class="pagination">
            <pagination :pageTotal="pageTotal" @handleCurrentChange="handleCurrentChange"
                        @handleSizeChange="handleSizeChange"></pagination>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import pagination from '../../common/pagination'
import bread from '../../common/bread'
import { formatDate } from 'src/utils/utils'
import {businessList, industryList, queryAddress} from '../../api/api'

const POSITIVE = 0
const NEGATIVE = 1

export default {
  data () {
    return {
      optionProps: {
        value: 'id',
        label: 'name',
        children: 'child'
      },
      selectedOptions: [],
      businessList: [],
      tabsName: '1',
      loading: true,
      incomePayData: {
        pageNum: 1,
        pageSize: 10,
        userId: sessionStorage.getItem('userId'),
        mobile: '',
        shopName: '',
        classifyId: '',
        shopCode: '',
        province: '',
        city: '',
        county: ''
      },
      pageTotal: 0,
      value: '',
      tradeList: [],
      tradeValue: '',
      multipleSelection: [],
      frozen: [],
      editForm: []
    }
  },
  created () {

  },
  mounted () {
    this.getTableData()
    this.getTradeList()
    this.queryAddress()
  },
  methods: {
    // 显示编辑界面
    onEdit (index, row) {
      this.editForm = Object.assign({}, row)
      this.$router.push({ name: 'businessEdit', params: { formData: this.editForm } })
    },
    onCheck (index, row) {
      this.editForm = Object.assign({}, row)
      this.$router.push({ name: 'businessLook', params: { formData: this.editForm } })
    },
    // 获取列表数据 num(下同):取的挪车的原型 1-默认请求类型三方ID
    // 网点名称 storeName ID cardId
    submitSearch () {
      this.getTableData()
    },
    // 格式化表单数据
    clearForm () {
      this.incomePayData = {
        pageNum: 1,
        pageSize: 10,
        userId: sessionStorage.getItem('userId'),
        mobile: '',
        shopName: '',
        classifyId: '',
        shopCode: '',
        province: '',
        city: '',
        county: ''
      }
    },
    // 清除列表的搜索表单
    clearListSearch () {
      this.clearForm()
      this.selectedOptions = []
      this.getTableData()
    },

    // 冻结商家
    frozenBusiness () {
      // this.delVisible = true
      // 显示删除弹框
      const length = this.multipleSelection.length

      for (let i = 0; i < length; i++) {
        this.frozen.push(this.multipleSelection[i].businessId)
      }
      if (this.frozen.length === 0) {
        console.log(111)
      }
    },

    handleSelectionChange (val) {
      this.multipleSelection = val
    },

    show (scope) {
      console.log(scope)
    },

    getTableData () {
      this.businessList = []
      const para = Object.assign({}, this.incomePayData)
      businessList(para).then(res => {
        this.businessList = res.data.list
        this.pageTotal = res.data.total
        console.log(res)
      })
    },

    // 上下分页
    handleCurrentChange (val) {
      this.incomePayData.pageNum = val
      this.getTableData()
    },
    // 每页显示多少条
    handleSizeChange (val) {
      this.incomePayData.pageSize = val
      this.getTableData()
    },
    queryAddress() {
      queryAddress().then(res => {
        this.optionProps = res.data;
      })
    },
    handleChange (value) {
      let labels = this.$refs['address'].getCheckedNodes()[0].pathLabels;
      this.incomePayData.province = labels[0];
      this.incomePayData.city = labels[1] === '全部' ? '' : labels[1];
      this.incomePayData.county = labels[2] === '全部' ? '' : labels[2];
    },

    // 行业接口
    getTradeList () {
      const para = Object.assign({})
      industryList(para).then(res => {
        this.tradeList = res.data
        console.log(this.tradeList)
      })
    },
    addRowClass ({ row, rowIndex }) {
      if (row.rateType === NEGATIVE) {
        return 'warning-row'
      }
    }
  },
  filters: {
    rateTypeToText (rateType) {
      return rateType === POSITIVE ? '满意' : '不满意'
    },
    formatDate (time) {
      let date = new Date(time)
      return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
    }
  },
  components: {
    pagination,
    bread
  }
}
</script>
<style lang='scss'>

  .el-dialog--small {
    width: 600px !important;
  }

  .container {
    .el-table {
      .warning-row {
        background-color: oldlace;
      }
    }

    .recommend-tag {
      display: inline-block;
      margin: 4px 0;
      margin-right: 4px;

      &:last-child {
        margin-right: 0;
      }
    }

    .table-footer {
      padding: 10px;
      background: #eef1f6;
    }
  }
</style>
